package com.wandian.cqcsk.mvvm.mine.invite.invitereward.mthtickethistory;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.mylib.libcore.adapter.BasePagerAdapter;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.StatusBarUtils;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.cqcsk.R;
import com.wandian.cqcsk.databinding.ActivityInviteHistoryBinding;
import com.wandian.cqcsk.mvvm.mine.invite.invitereward.mthtickethistory.invitehistorypagefragment.InviteHistoryPageFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 邀请记录
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_INVITE_RECORD)
public class InviteHistoryActivity extends BaseMVVMActivity<InviteHistoryActivityViewModel> {
    private ActivityInviteHistoryBinding dataBinding;
    private BasePagerAdapter myAdapter;
    private List<String> titleList=new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();
    private String friends_json;
    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_invite_history);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        friends_json = getIntent().getStringExtra("friends_json")+"";
        initViewData();
        initTabPage();
        initClink();
    }
    private void initViewData(){
        //设置状态颜色和字体黑色
        StatusBarUtils.with(this,false)
                .setIsActionBar(false)
                .clearActionBarShadow()
                .setDrawable(getResources().getDrawable(com.mylib.libcore.R.drawable.sys_color))
                .init();
        dataBinding.bindSysToolBar.toolBarTvTitle.setText("邀请记录");

    }
    private void initClink(){
        dataBinding.bindSysToolBar.toolBarIvBack.setOnClickListener(v -> {
            finishhideSoftBoard();
            finish();
        });
    }

    //初始化tabpage
    private void initTabPage() {
        titleList.clear();
        fragments.clear();
        titleList.add(" 我的好友 ");
        titleList.add(" 完成进度 ");
        for(int i=0;i<titleList.size();i++){
            fragments.add(InviteHistoryPageFragment.newInstance(titleList.get(i).trim(),friends_json));
        }

        myAdapter = new BasePagerAdapter(getSupportFragmentManager(), fragments,titleList);
        if(UIUtils.isEmpty(dataBinding.viewPager.getAdapter())){
            dataBinding.viewPager.setAdapter(myAdapter);
            dataBinding.viewPager.setOffscreenPageLimit(titleList.size());
            dataBinding.tabLayout.setViewPager(dataBinding.viewPager);
        }
        if(!UIUtils.isEmpty(myAdapter)){
            myAdapter.notifyDataSetChanged();
        }
        //预加载数量
        dataBinding.viewPager.setOffscreenPageLimit(1);
        dataBinding.tabLayout.setViewPager(dataBinding.viewPager);
        dataBinding.tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
        dataBinding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }

}
